package com.ruoyi.dynamic.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.dynamic.domain.UserDynamic;
import com.ruoyi.dynamic.mapper.UserDynamicMapper;
import com.ruoyi.dynamic.service.IUserDynamicService;
import com.ruoyi.order.domain.OrderInfo;
import com.ruoyi.order.service.IOrderInfoService;

import cn.hutool.core.collection.CollectionUtil;

/**
 * 用户发布动态/活动Service业务层处理
 * 
 * @author DEREK
 * @date 2023-08-08
 */
@Service
public class UserDynamicServiceImpl extends ServiceImpl<UserDynamicMapper, UserDynamic> implements IUserDynamicService 
{
    @Autowired
    private UserDynamicMapper userDynamicMapper;
    @Autowired
    private IOrderInfoService orderInfoService;
    
    /**
     * 查询用户发布动态/活动
     * 
     * @param id 用户发布动态/活动主键
     * @return 用户发布动态/活动
     */
    @Override
    public UserDynamic selectUserDynamicById(Long id)
    {
        return userDynamicMapper.selectUserDynamicById(id);
    }

    /**
     * 查询用户发布动态/活动列表
     * 
     * @param userDynamic 用户发布动态/活动
     * @return 用户发布动态/活动
     */
    @Override
    public List<UserDynamic> selectUserDynamicList(UserDynamic userDynamic)
    {
        return userDynamicMapper.selectUserDynamicList(userDynamic);
    }

    /**
     * 新增用户发布动态/活动
     * 
     * @param userDynamic 用户发布动态/活动
     * @return 结果
     */
    @Override
    public int insertUserDynamic(UserDynamic userDynamic)
    {
        userDynamic.setCreateTime(DateUtils.getNowDate());
        return userDynamicMapper.insertUserDynamic(userDynamic);
    }

    /**
     * 修改用户发布动态/活动
     * 
     * @param userDynamic 用户发布动态/活动
     * @return 结果
     */
    @Override
    public int updateUserDynamic(UserDynamic userDynamic)
    {
        return userDynamicMapper.updateUserDynamic(userDynamic);
    }

    /**
     * 批量删除用户发布动态/活动
     * 
     * @param ids 需要删除的用户发布动态/活动主键
     * @return 结果
     */
    @Override
    public int deleteUserDynamicByIds(Long[] ids)
    {
        return userDynamicMapper.deleteUserDynamicByIds(ids);
    }

    /**
     * 删除用户发布动态/活动信息
     * 
     * @param id 用户发布动态/活动主键
     * @return 结果
     */
    @Override
    public int deleteUserDynamicById(Long id)
    {
        return userDynamicMapper.deleteUserDynamicById(id);
    }

	@Override
	public void batchUpdateOrder(Long id,String type) {
		List<OrderInfo> list = orderInfoService.list(new LambdaQueryWrapper<OrderInfo>().eq(OrderInfo::getRelatedId, id));
		if(CollectionUtil.isNotEmpty(list)) {
			list.stream().forEach(order ->{
				order.setOrderStatus(type);
			});
			orderInfoService.updateBatchById(list);
		}
	}
}
